<?php
/*******************************************************
系统配置信息的获取，全局共享的业务逻辑
 *******************************************************/
namespace src\logic;
use \classlib\core as C;
class lconfig {
	//兑换比例
	const STARRATIO = 100;
	//转换成币
	const CANRATIO  = 100;
	/**
	 * 获取配置选项资料信息
	 * @param string $key
	 * @return dict array
	 */
	public static function dd($key) {
		$str   = self::str($key);
		$dict  = array();
		$arr   = explode(';', $str);
		foreach ($arr as $value) {
			list($key, $val) = explode('=', $value);
			$dict[$key] = $val;
		}
		return $dict;
	}
	
	/**
	 * 获取配置选项资料信息
	 * @param string $key
	 * @return array
	 */
	public static function ddarr($key) {
		$str   = self::str($key);
		$result= array();
		$arr   = explode(';', $str);
		foreach ($arr as $value) {
			if (empty($value)) {
				continue;
			}
			list($key, $val) = explode('=', $value);
			$result[] = array($key, $val);
		}
		return $result;
	}
	
	/**
	 * 获取配置选项资料信息
	 * @param string $key
	 * @return string
	 */
	public static function str($key) {
		$orm   = C\model::load('main.sys.config');
		$where = array('`key`'=>$key);
		$conf  = $orm->get_item($where);
		return $conf? $conf['value']:null;	
	}
	
	/**
	 * 获取配置选项资料信息 返回json对象
	 * @param string $key
	 * @return array | null
	 */
	public static function jsonarr($key) {
		$value = self::str($key);
		return $value? json_decode($value, true):null;
	}
	
	/**
	 * 获取配置选项资料信息 返回xml对象
	 * @param string $key
	 * @return array | null
	 */
	public static function xmlarr($key) {
		$value = self::str($key);
		return $value? \classlib\xmlparser::xml2array($value):null;
	}
}